package Iot;

import java.security.MessageDigest;

public class MD5Util {
    //private static final String slat = "&%5123***&&%%$$#@";
    /**
     *@Author: caoxiabo on 2019/12/17 16:00
     *@Description: 极光通信 IM 加密方式
     */
    private static final String slat = "";

    public static void main(String[] args) {
        long mm = System.currentTimeMillis();
        System.out.println("mm:" + mm);
        //String str = "appkey=1493f56d35c2f714ec0d61db&timestamp=1507882399401&random_str=808&key=429d4bfe6a67188a3a0f088d";

        String str = "appkey=1493f56d35c2f714ec0d61db&timestamp=" + mm + "&random_str=606&key=429d4bfe6a67188a3a0f088d";
        String e_str = encrypt(str);
        System.out.println("加密："+e_str);
    }

    private static String encrypt(String dataStr) {
        try {
            dataStr = dataStr + slat;
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(dataStr.getBytes("UTF8"));
            byte s[] = m.digest();
            String result = "";
            for (int i = 0; i < s.length; i++) {
                result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
